package com.yy.device.boot.protocol;

import com.yy.device.enums.DeviceDataEnum;
import com.yy.device.enums.DeviceFunctionEnum;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

/**
 * 任务消息
 *
 * @author zhiqiang.sun
 * @date 2022/06/21
 */
@Slf4j
@Data
@EqualsAndHashCode(callSuper = true)
public class TaskQueryMessage extends Message {

    private byte head;
    private byte version;
    private short length;
    private long taskId;
    private byte address;
    private DeviceFunctionEnum deviceFunctionEnum;
    private short devicePointCode;
    private DeviceDataEnum deviceDataEnum;
    private short crcMod;
    private short crc;
    private byte end;

    @Override
    public void decode(ByteBuf byteBuf) {
        this.setTaskId(byteBuf.readLongLE());
        this.setAddress(byteBuf.readByte());
        this.setDeviceFunctionEnum(DeviceFunctionEnum.getEnumByType(byteBuf.readByte() & 0xff));
        this.setDevicePointCode(byteBuf.readShortLE());
        this.setDeviceDataEnum(DeviceDataEnum.getEnumByType((short) (byteBuf.readByte() & 0xff)));
        this.setCrcMod(byteBuf.readShortLE());
        this.setCrcMod(byteBuf.readShortLE());
    }
}
